<?php
/**
 * Created by PhpStorm.
 * User: zcq
 * Date: 2019/4/4
 * Time: 17:47
 */

namespace app\index\controller;


use think\Cookie;
use think\Db;

class Code extends Base
{
    public function index()
    {
        $code = input('code');
        $key = 'scgc';
        $cookie = Cookie::get($key);
        if(!$cookie){
            //计数
            if($code){
                $a = Db::name('qrcode')->where('code',$code)->find();
                if($a){
                    $data = [
                        'qrcode_id'=>$a['id'],
                        'ip'=>request()->ip(),
                        'addtime'=>time(),
                    ];
                    Db::name('qrcode_record')->insert($data);
                    Db::name('qrcode')->where('id',$a['id'])->setInc('nums');
                }
            }
            $expire = 7*24*3600;
            $res = Cookie::set($key,time(),$expire);
        }
        return $this->fetch();

    }
}